/**
 * Created by asus on 2017/5/5.
 */
const faker = require('faker')
const lib = require('lodash')
faker.locale = 'zh_CN'

module.exports = {
  api: '/codi-admin-mock/sys/news',
  response: function (req, res) {
    console.log(req.query)
    console.log(req.method)
    if (req.method === 'GET') {
      let index = parseInt(req.query.page)
      let size = parseInt(req.query.size)
      const total = 36
      const page = Math.ceil(total / size)
      let resNum = index >= page ? (total - (index - 1) * size) : size
      let content = '这是标题'
      let data = {
        'success': true,
        'objs': lib.times(resNum, function (n) {
          return {
            'content': '这是征文',
            'from': '腾讯证券',
            'fromUrl': 'http://baidu.com',
            'id': n + ((index - 1) * size),
            'keyword': '老虎 QFII',
            'location': (n % 2 === 1) ? 'PC' : 'APP',
            'modifyDate': 1493802512051,
            'publishDate': 1493802512051,
            'publisher': 'admin',
            'status': (n % 2 === 1) ? '上线' : '下线',
            'title': content + (n + ((index - 1) * size))
          }
        }),
        'page': index,
        'rowCount': resNum,
        'size': resNum,
        'totalNum': total,
        'totalPage': page
      }
      res.json(data)
    } else if (req.method) {
      res.json({
        'success': true,
        'result': {
          'content': '这是征文',
          'from': '腾讯证券',
          'fromUrl': 'http://baidu.com',
          'id': 1,
          'keyword': '老虎 QFII',
          'location': 'PC',
          'modifyDate': 1493802912819,
          'publishDate': 1493802912819,
          'publisher': 'admin',
          'status': '上线',
          'title': '这是标题'
        }
      })
    } else if (req.method === 'DELETE') {
      res.json(
        {
          'success': true,
          'result': 1
        }
      )
    }
  }
}
